#coding:utf-8
#python BilibiliDanmuShow.py link

import requests
import re
import sys
import threading

MsgNum = 0
url = sys.argv[1]
danmuId = re.search(r"cid=(.*?)&aid=",requests.get(url=url).content).group(1)

#刷新弹幕内容
def flashDanmu():
    global danmuId
    url = "http://comment.bilibili.com/"+danmuId+".xml"
    msgs = requests.get(url=url).content
    msgData = re.compile("<d p=.*?>(.*?)</d>").findall(msgs)
    global MsgNum
    if len(msgData) > MsgNum:
        for i in range ( MsgNum , len(msgData) ):
            print msgData[i].decode("utf-8")
        MsgNum = len(msgData)
    threading.Timer(3,flashDanmu).start()


flashDanmu()